package com.staginfo.segs.util;

import android.content.Context;
import android.widget.Toast;

/**
 * 吐司提示类
 *
 * @author jack.wuxiazhi
 */
public class ToastUtil {
    private Toast toast;
    private static ToastUtil instance;

    private ToastUtil(Context context) {
        this.toast = Toast.makeText(context.getApplicationContext(), "", Toast.LENGTH_SHORT);
    }

    public static ToastUtil getInstance(Context context) {
        if (instance == null) {
            if (instance == null) {
                synchronized (ToastUtil.class) {
                    if (instance == null) {
                        instance = new ToastUtil(context);
                    }
                }
            }
        }
        return instance;
    }

    /**
     * 短提示
     *
     * @param text
     */
    public synchronized void shortToast(String text) {
        try {
            toast.setText(text);
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.show();
        } catch (Exception e) {
            LogUtils.d("zxc", "主线程也出错..." + Thread.currentThread() + " error:" + e.toString());
        }
    }

    /**
     * 长提示
     * @param text
     */
    public synchronized void longToast(String text) {
        try {
            toast.setText(text);
            toast.setDuration(Toast.LENGTH_LONG);
            toast.show();
        } catch (Exception e) {
            LogUtils.d("zxc", "主线程也出错..." + Thread.currentThread() + " error:" + e.toString());
        }
    }
}
